<?php
namespace app\admin\model;
use think\Model;
class Module extends Model
{   
    public function getModuleByParentId($list,$parentId="0",$level=0){
       // dump($list);
        static $arr=[];
        foreach($list as $k=>$vo){
            if($vo['parent_id']==$parentId){
                $vo['level']=$level;
                $vo['str']=str_repeat('--',$vo['level']);
                $arr[]=$vo;
                $this->getModuleByParentId($list,$vo['id'],$level+1);//递归函数
            }
        }
        return $arr;  
    }
   //为获得多维数组
    public function getModucates($list,$parentId='0'){
      $arr=[];
      foreach($list as $k=>$vo){
          if($vo['parent_id']==$parentId){
              $vo['child']=$this->getModucates($list,$vo['id']);
              $arr[]=$vo;
              
          }
      }
      
      return $arr;  
        
    }
    
    
}
